package com.itheima.consumer.mp.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ErrorMessageConfig {
    @Bean
    public DirectExchange exchange()
    {
        return new DirectExchange("error.exchange");
    }
    @Bean
    public Queue queue()
    {
        return new Queue("error.queue");
    }
    @Bean
    public Binding binding(Queue queue,DirectExchange exchange)
    {
        return BindingBuilder.bind(queue).to(exchange).with("error");
    }

    @Bean
    public RepublishMessageRecoverer republishMessageRecoverer(RabbitTemplate rabbitTemplate)
    {
        return new RepublishMessageRecoverer(rabbitTemplate,"error.exchange","error");
    }

}
